﻿using System;
using System.Xml.Serialization;

namespace KBEngine.Setting.Internal
{
    [Serializable]
    public class CellApp
    {
        /// <summary>
        /// 脚本入口模块， 相当于main函数
        /// </summary>
        public string entryScriptFile = "kbemain";

        /// <summary>
        /// 默认View半径, 脚本中可以改变它 
        /// </summary>
        public DefaultViewRadius defaultViewRadius = new DefaultViewRadius();

        /// <summary>
        /// 优化EntityID，View范围内实体数小于255个, EntityID传输到client时使用1字节别名ID
        /// </summary>
        public bool aliasEntityID = true;

        /// <summary>
        /// 优化Entity属性和方法在广播时所消耗的带宽，Entity客户端属性或者客户端方法不超过255时， 
        /// 方法uid和属性uid传输到client时使用1字节别名ID
        /// </summary>
        public bool entitydefAliasID = true;

        /// <summary>
        /// 指定接口地址，可配置网卡名、MAC、IP
        /// </summary>
        public string internalInterface = string.Empty;

        /// <summary>
        /// entityID分配器，进入溢出范围则请求获取新的ID资源 
        /// </summary>
        public CellApp_Ids ids = new CellApp_Ids();

        /// <summary>
        /// 程序的性能分析
        /// </summary>
        public Profiles profiles = new Profiles();

        /// <summary>
        /// 负载平衡滤波器指标值
        /// </summary>
        public float loadSmoothingBias = 0.01f;

        public float ghostDistance = 500.0f;
        public ushort ghostingMaxPerCheck = 64;

        /// <summary>
        /// ghost更新频率
        /// </summary>
        public ushort ghostUpdateHertz = 30;

        public CoordinateSystem coordinate_system = new CoordinateSystem();

        public TelnetService telnet_service = new TelnetService();

        public Shutdown shutdown = new Shutdown();

        public Witness witness = new Witness();

        /// <summary>
        /// listen监听队列最大值
        /// </summary>
        [XmlElement("SOMAXCONN")]
        public uint somaxconn = 511;

        [Serializable]
        public class CellApp_Ids
        {
            public int criticallyLowSize = 1000;
        }

        [Serializable]
        public class Shutdown
        {
            /// <summary>
            /// 每秒销毁有base部分的entity的数量
            /// </summary>
            public uint perSecsDestroyEntitySize = 100;
        }
        [Serializable]
        public class Witness
        {
            /// <summary>
            /// 当一个实体不再被观察者观察之后，实体并不会马上恢复为未被观察状态，在timeout(秒)时间范围内没有再次被观察则重置状态
            /// </summary>
            public ushort timeout = 15;
        }

        [Serializable]
        public class DefaultViewRadius
        {
            public float radius = 80.0f;
            public float hysteresisArea = 5.0f;
        }

        [Serializable]
        public class CoordinateSystem
        {
            public bool enable = true;

            /// <summary>
            /// 是否管理y轴? 注：管理y轴，则View、Trap等功能有了高度，当space内的实体较少时比较好用，
            /// 否则y轴的管理会带来一些消耗
            /// </summary>
            public bool rangemgr_y = false;

            /// <summary>
            /// 实体位置停止发生改变后，引擎继续向客户端更新tick次的位置信息，为0则总是更新。
            /// </summary>
            public ushort entity_posdir_additional_updates = 2;
            public EntityPosdirUpdates entity_posdir_updates = new EntityPosdirUpdates();

            [Serializable]
            public class EntityPosdirUpdates
            {
                public ushort type = 2;
                public ushort smartThreshold = 10;
            }
        }
    }

}
